﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ARR.Entities.Gateways;

namespace ARR.Entities
{
    [DataContract]
    [Serializable]
    public class SalesCategoryComparisonPareto : EntityBase
    {
        [DataMember]
        SalesCategoryComparisonParetoRow row;

        public SalesCategoryComparisonPareto(SalesCategoryComparisonParetoRow row)
        {
            this.row = row;
        }

        public SalesCategoryComparisonPareto()
        {
            row = new SalesCategoryComparisonParetoRow();
        }

        public override void Initialize()
        {
            row = new SalesCategoryComparisonParetoRow();
        }

        [DataMember]
        public int Ranking { get; set; }

        [DataMember]
        public decimal PrevAcumSales { get; set; }

        [DataMember]
        public decimal AcumSales { get; set; }

        [DataMember]
        public decimal AcumSKUs { get; set; }

        [DataMember]
        public int Id
        {
            get { return row.Id; }
            set { row.Id = value; }
        }

        [DataMember]
        public string Code
        {
            get { return row.Code; }
            set { row.Code = value; }
        }

        [DataMember]
        public string Name
        {
            get { return row.Name; }
            set { row.Name = value; }
        }

        [DataMember]
        public string Brand
        {
            get { return row.Brand; }
            set { row.Brand = value; }
        }

        [DataMember]
        public string Manufacturer
        {
            get { return row.Manufacturer; }
            set { row.Manufacturer = value; }
        }

        [DataMember]
        public decimal Units
        {
            get { return row.Units; }
            set { row.Units = value; }
        }

        [DataMember]
        public decimal UnitsInCombos
        {
            get { return row.UnitsInCombos; }
            set { row.UnitsInCombos = value; }
        }

        [DataMember]
        public decimal Sales
        {
            get { return row.Sales; }
            set { row.Sales = value; }
        }

        [DataMember]
        public decimal GM
        {
            get { return row.GM; }
            set { row.GM = value; }
        }

        [DataMember]
        public decimal Coverage
        {
            get { return row.Coverage; }
            set { row.Coverage = value; }
        }

        [DataMember]
        public decimal StoreCoverage
        {
            get { return row.StoreCoverage; }
            set { row.StoreCoverage = value; }
        }

        [DataMember]
        public int StoreCoverageQuantity
        {
            get { return row.StoreCoverageQuantity; }
            set { row.StoreCoverageQuantity = value; }
        }

        [DataMember]
        public decimal MonthsCoverage
        {
            get { return row.MonthsCoverage; }
            set { row.MonthsCoverage = value; }
        }

        [DataMember]
        public int MonthsCoverageQuantity
        {
            get { return row.MonthsCoverageQuantity; }
            set { row.MonthsCoverageQuantity = value; }
        }
        
        [DataMember]
        public string Category
        {
            get { return row.Category; }
            set { row.Category = value; }
        }

        [DataMember]
        public short CategoryId
        {
            get { return row.CategoryId; }
            set { row.CategoryId = value; }
        }

        [DataMember]
        public short SubcategoryId
        {
            get { return row.SubcategoryId; }
            set { row.SubcategoryId = value; }
        }

        [DataMember]
        public string Subcategory
        {
            get { return row.Subcategory; }
            set { row.Subcategory = value; }
        }

        [DataMember]
        public string MC
        {
            get { return row.MC; }
            set { row.MC = value; }
        }

        [DataMember]
        public string Attribute1
        {
            get { return row.Attribute1; }
            set { row.Attribute1 = value; }
        }

        [DataMember]
        public string Attribute2
        {
            get { return row.Attribute2; }
            set { row.Attribute2 = value; }
        }

        [DataMember]
        public string Attribute3
        {
            get { return row.Attribute3; }
            set { row.Attribute3 = value; }
        }

        [DataMember]
        public string Attribute4
        {
            get { return row.Attribute4; }
            set { row.Attribute4 = value; }
        }

        [DataMember]
        public string Attribute5
        {
            get { return row.Attribute5; }
            set { row.Attribute5 = value; }
        }

        [DataMember]
        public bool Delist
        {
            get { return row.Delist; }
            set { row.Delist = value; }
        }
        
        [DataMember]
        public string DelistComment
        {
            get { return row.DelistComment; }
            set { row.DelistComment = value; }
        }

        [DataMember]
        public bool IsDeletedRangeReview
        {
            get { return row.IsDeletedRangeReview; }
            set { row.IsDeletedRangeReview = value; }
        }

        [DataMember]
        public bool IsDeletedPerformance
        {
            get { return row.IsDeletedPerformance; }
            set { row.IsDeletedPerformance = value; }
        }

        [DataMember]
        public bool IsDelisted
        {
            get { return row.IsDelisted; }
            set { row.IsDelisted = value; }
        }

        [DataMember]
        public bool IsNew
        {
            get { return row.IsNew; }
            set { row.IsNew = value; }
        }

        [DataMember]
        public decimal InventoryCost
        {
            get { return row.InventoryCost; }
            set { row.InventoryCost = value; }
        }

        [DataMember]
        public decimal PIDiff
        {
            get { return row.PIDiff; }
            set { row.PIDiff = value; }
        }

        [DataMember]
        public decimal ChargeOffs
        {
            get { return row.ChargeOffs; }
            set { row.ChargeOffs = value; }
        }

        [DataMember]
        public decimal Rebates
        {
            get { return row.Rebates; }
            set { row.Rebates = value; }
        }

        [DataMember]
        public decimal Width
        {
            get { return row.Width; }
            set { row.Width = value; }
        }

        [DataMember]
        public decimal Facings
        {
            get { return row.Facings; }
            set { row.Facings = value; }
        }
        
        [DataMember]
        public bool IsPriorYear
        {
            get { return row.IsPriorYear; }
            set { row.IsPriorYear = value; }
        }

        [DataMember]
        public decimal TheoreticalMargin
        {
            get { return row.TheoreticalMargin; }
            set { row.TheoreticalMargin = value; }
        }

        [DataMember]
        public string Segment
        {
            get { return row.Segment; }
            set { row.Segment = value; }
        }

        
        //CALCULATED PROPERTIES
        
        public decimal LinearSpace
        {
            get
            {
                return Width * Facings / 100;
            }
        }
        
        public decimal GMPercent
        {
            get
            {
                return Sales != 0 ? GM / Sales : 1;
            }
        }

        public decimal GMPerSKU
        {
            get
            {
                return Units != 0 ? GM / Units : 0;
            }
        }
        
        public decimal InvDays
        {
            get
            {
                return (Sales - GM) != 0 ? InventoryCost / ((Sales - GM) / 30) : 0;
            }
        }

        public decimal AnnualStockTurn
        {
            get
            {
                return InvDays != 0 ? 365 / InvDays : 0;
            }
        }

        public decimal GMROI
        {
            get
            {
                return InventoryCost != 0 ? GM / InventoryCost : 0;
            }
        }
        
        public decimal SalesOverLinearMt
        {
            get
            {
                return LinearSpace != 0 ? Sales / LinearSpace : 0;
            }
        }

        public decimal GMROS
        {
            get
            {
                return LinearSpace != 0 ? GM / LinearSpace : 0;
            }
        }
        
        public decimal AveragePrice
        {
            get
            {
                return Units != 0 ? Sales / Units : 0;
            }
        }

        public bool HasSales
        {
            get
            {
                return Sales != 0 || GM != 0 || Units != 0;
            }
        }

    }
}
